from django.db import models
from personal.models import User


# Create your models here.


class Spit(models.Model):
    SPIT_STATUS = (
        (0, '通过审核'),
        (1, '未通过审核'),
    )
    author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='吐槽作者id')
    content = models.TextField(verbose_name='吐槽内容')
    create_time = models.DateTimeField(verbose_name='吐槽生成时间')
    like_count = models.IntegerField(verbose_name='点赞量', default=0)
    comment_count = models.IntegerField(verbose_name='评论量', default=0)
    status = models.SmallIntegerField(choices=SPIT_STATUS, verbose_name='审核状态', default=0)

    class Meta:
        db_table = 'tb_spit'
        verbose_name = '吐槽'
        verbose_name_plural = verbose_name


class SpitComments(models.Model):
    author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='评论作者id')
    spit = models.ForeignKey(Spit, on_delete=models.CASCADE, verbose_name='吐槽id')
    content = models.TextField(verbose_name='评论内容')
    create_time = models.DateTimeField(verbose_name='评论生成时间')
    like_count = models.IntegerField(verbose_name='点赞量', default=0)
    parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, verbose_name='父评论id')

    class Meta:
        db_table = 'tb_spit_comments'
        verbose_name = '吐槽评论'
        verbose_name_plural = verbose_name


class SpitLike(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='吐槽作者id')
    spit = models.ForeignKey(Spit, on_delete=models.CASCADE, verbose_name='吐槽id')

    class Meta:
        db_table = 'tb_spit_like'
        verbose_name = '点赞吐槽'
        verbose_name_plural = verbose_name


class CommentsLike(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='评论作者id')
    comment = models.ForeignKey(SpitComments, on_delete=models.CASCADE, verbose_name='评论id')

    class Meta:
        db_table = 'tb_comments_like'
        verbose_name = '点赞评论'
        verbose_name_plural = verbose_name